﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Model;
using Manager;
using ExtAspNet;
namespace HealthSystem
{
    public partial class ChooseOrg : BasePage
    {
        HW_OrgUserManager manager = new HW_OrgUserManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                name.OnClientTriggerClick = Window1.GetSaveStateReference(districtid.ClientID, name.ClientID)
                    + Window1.GetShowReference("./ChooseDistrict.aspx","地区选择");
                this.actionbt.Text = "";
                BindGrid(CustomerProfile.DistrictId);
            }
        }
        public void BindGrid(string districtId)
        {
            int count = 0;
            DataTable list = manager.GetSubList(Gird1.PageIndex, Gird1.PageSize, out count, districtId);
            Gird1.RecordCount = count;
            Gird1.DataSource = list;
            Gird1.DataBind();

        }
        public void Grid1_DoubleClick(object sender,ExtAspNet.GridRowClickEventArgs e)
        {
            string orgcode = Gird1.Rows[e.RowIndex].DataKeys[1].ToString();
            string orgname = Gird1.Rows[e.RowIndex].DataKeys[2].ToString();
            PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(orgcode, orgname) + ActiveWindow.GetHidePostBackReference());
        }
        public void queding_Click(object sender, EventArgs e)
        {
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
           // string orgcode = Gird1.Rows[Gird1.SelectedRowIndex].DataKeys[1].ToString();
           // string orgname = Gird1.Rows[Gird1.SelectedRowIndex].DataKeys[2].ToString();
           // PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(orgcode, orgname));
           //PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        }
        protected void ff(object sender, ExtAspNet.GridCommandEventArgs e)
        {

            string orgcode = Gird1.Rows[e.RowIndex].DataKeys[1].ToString();
            string orgname = Gird1.Rows[e.RowIndex].DataKeys[2].ToString();
            PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(orgcode, orgname) + ActiveWindow.GetHidePostBackReference());
            //e.Node.
           //PageContext.RegisterStartupScript(ActiveWindow.GetWriteBackValueReference(e.Node.Text, e.Node.NodeID) + ActiveWindow.GetHidePostBackReference());
        }
        public void Window1_Close(object sender, ExtAspNet.WindowCloseEventArgs e)
        {
            if (!string.IsNullOrEmpty(districtid.Text))
            {
                BindGrid(districtid.Text.Trim());
            }
            else
            {
                BindGrid(CustomerProfile.DistrictId);
            }
        }
        public void PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
        {
            Gird1.PageIndex = e.NewPageIndex;
            try
            {
                if (actionbt.Text == "search")
                {
                    Gird1.IsDatabasePaging = false;
                }
                else
                {
                    if (!string.IsNullOrEmpty(districtid.Text))
                    {
                        BindGrid(districtid.Text.Trim());
                    }
                    else
                    {
                        BindGrid(CustomerProfile.DistrictId);
                    }
                }
            }
            catch
            {
                Alert.Show("数据错误");
            }
        }
        public void Search_Clik(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(searchbox.Text))
            {
                ExtAspNet.Alert.Show("请输入查询条件");
                return;
            }
            DataTable dt = manager.Search(CustomerProfile.DistrictId, searchbox.Text);
            Gird1.IsDatabasePaging = false;
            this.Gird1.DataSource = dt;
            this.Gird1.DataBind();
            actionbt.Text = "search";
        }
        public void Search(string searchString)
        {
            //string DistrictId = CustomerProfile.DistrictId;
            //int count = 0;
            //DataTable list = manager.Search(Gird1.PageIndex, Gird1.PageSize, out count, DistrictId, searchString);
            //Gird1.RecordCount = count;
            //this.Gird1.DataSource = list;
            //this.Gird1.DataBind();
            //this.actionbt.Text = "search";
        }
    }
}